package com.cj.controller;

import com.cj.Service.EmpService;
import com.cj.pojo.DeptPojo;
import com.cj.pojo.EmployeePojo;
import com.cj.vo.EmpPageVo;
import com.cj.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/emp/")
public class EmpController  {

    @Autowired
    EmpService empService;//

    // 返回页面
    @RequestMapping("index/*")
    public  String deptIndex(){
        return "pages/content/emp_list";
    }

    // 分页显示列表
    @RequestMapping("page")
    @ResponseBody
    public JsonResult queryEmpPage(EmpPageVo empPageVo){
//        System.out.println("分页显示："+empPageVo.toString());
        List<EmployeePojo> list = empService.queryEmpPage(empPageVo);
        return new JsonResult(1,"成功",list );
    }
    // 分页显示列表
   @RequestMapping("count")
   @ResponseBody
    public JsonResult countEmp(EmployeePojo employeePojo ){
//        System.out.println("分页显示："+employeePojo.toString());
        Integer countEmp = (empService.countEmp(employeePojo)-1)/15+1;
        return new JsonResult(1,"成功",countEmp );
    }

    @RequestMapping("add")
    @ResponseBody
    public JsonResult addEmp(EmployeePojo employeePojo){
        System.out.println("新增参数："+employeePojo.toString());
        empService.addEmployee(employeePojo);
        return new JsonResult(1,"成功",null );
    }

    // 修改部门
    @RequestMapping("updata")
    @ResponseBody
    public JsonResult updataEmp(EmployeePojo employeePojo){
        empService.updataEmp(employeePojo);
        return  new JsonResult(1,"成功" ,null);
    }

    // 批量删除
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult deleteLogs(Integer[] ids){
        empService.deleteEmp(ids);
        return new JsonResult(1,"成功",null );
    }

}
